﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Login.BLL;

namespace Courses
{
    public partial class tb_shiyanclass : Form
    {
        public tb_shiyanclass()
        {
            InitializeComponent();
        }
        string banJiID = "";   //班级id类

        //按钮项实例
        #region
        CheckBox dianJiOne = new CheckBox();
        CheckBox dianJiTwo = new CheckBox();
        CheckBox dianJiThree = new CheckBox();
        CheckBox dianJiFour = new CheckBox();
        CheckBox dianJiFive = new CheckBox();
        CheckBox dianJiSix = new CheckBox();
        CheckBox dianJiSeven = new CheckBox();
        CheckBox dianJiEight = new CheckBox();
        CheckBox dianJiNine = new CheckBox();
        CheckBox dianJiTen = new CheckBox();
        #endregion


        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region
        private void tb_shiyanclass_Load(object sender, EventArgs e)
        {
            //提取导入的所有实验
            shiYanXiang();
            //提取班级名
            Bind();
        }
        #endregion


        /// <summary>
        /// 提取表格方法
        /// </summary>
        #region
        public void Bind()
        {
            //提取班级名称表
            DataSet ds = tb_shiyanclassBLL.getData();
            //添加到窗体中
            biao.DataSource=ds.Tables[0];
        }
        #endregion


        /// <summary>
        /// 表格点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region
        private void biao_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //选中的实验名选项清空
            Empty();
            //提取实验名称
            string banJiName = Convert.ToString(biao.SelectedRows[0].Cells[1].Value.ToString());
            //提取实验名称ID
            banJiID = Convert.ToString(biao.SelectedRows[0].Cells[0].Value.ToString());
            zhuanye.Text = banJiName;
            //提取班级所有实验ID
            string[] str = tb_shiyanclassBLL.getExpermentIdZu(banJiName);
            //循环遍历每一个实验ID
            for (int i = 0; i < str.Length; i++)
            {
                //选中该班级已安排的实验ID
                Select(str[i]);
            }
        }
        #endregion

        /// <summary>
        /// 选中该班级已安排的实验ID
        /// </summary>
        /// <param name="shiYanID">实验ID</param>
        #region
        public void Select(string shiYanID)
        {
            //判断哪些被选中
            switch (shiYanID)
            {
                case "1":
                    dianJiOne.Checked = true;
                    break;
                case "2":
                    dianJiTwo.Checked = true;
                    break;
                case "3":
                    dianJiThree.Checked = true;
                    break;
                case "4":
                    dianJiFour.Checked = true;
                    break;
                case "5":
                    dianJiFive.Checked = true;
                    break;
                case "6":
                    dianJiSix.Checked = true;
                    break;
                case "7":
                    dianJiSeven.Checked = true;
                    break;
                case "8":
                    dianJiEight.Checked = true;
                    break;
                case "9":
                    dianJiNine.Checked = true;
                    break;
                case "10":
                    dianJiTen.Checked = true;
                    break;
            }
        }
        #endregion

        /// <summary>
        /// 选中的实验名选项清空
        /// </summary>
        #region
        public void Empty()
        {
            dianJiOne.Checked = false;
            dianJiTwo.Checked = false;
            dianJiThree.Checked = false;
            dianJiFour.Checked = false;
            dianJiFive.Checked = false;
            dianJiSix.Checked = false;
            dianJiSeven.Checked = false;
            dianJiEight.Checked = false;
            dianJiNine.Checked = false;
            dianJiTen.Checked = false;
        }
        #endregion

        /// <summary>
        /// 添加实验事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region
        private void btn_Click(object sender, EventArgs e)
        {
            try
            {
                //判断是否选中班级
                if (banJiID=="")
                {
                    MessageBox.Show("请先选择班级再添加实验！");
                    return;
                }
                //删除班级原有的实验
                tb_shiyanclassBLL.delete(banJiID);
                //添加选中的班级
                ExpermentAdd();
                MessageBox.Show("添加成功！！");
            }
            catch
            {

                MessageBox.Show("添加实验失败!");
            }
        }
        #endregion

        /// <summary>
        /// 添加选中的班级
        /// </summary>
        #region
        public void ExpermentAdd()
        {
            try
            {
                //判断是否选中
                if (dianJiOne.Checked == true)
                {
                    //如果选中添加当前实验
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "1");
                }
                if (dianJiTwo.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "2");
                }
                if (dianJiThree.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "3");
                }
                if (dianJiFour.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "4");
                }
                if (dianJiFive.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "5");
                }
                if (dianJiSix.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "6");
                }
                if (dianJiSeven.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "7");
                }
                if (dianJiEight.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "8");
                }
                if (dianJiNine.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "9");
                }
                if (dianJiTen.Checked == true)
                {
                    tb_shiyanclassBLL.ExpermentAdd(banJiID, "10");
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        #endregion

        /// <summary>
        /// 提取导入的所有实验
        /// </summary>
        #region
        public void shiYanXiang()
        {
            try
            {
                //判断实验是否存在
                if (tb_shiyanclassBLL.ExperimentNameJudge(1) != "")
                {
                    //如果存在，添加到窗体
                    dianJiOne.Location = new Point(243, 81);
                    this.Controls.Add(dianJiOne);
                    dianJiOne.Text = tb_shiyanclassBLL.ExperimentNameJudge(1).ToString();
                    dianJiOne.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(2) != "")
                {
                    dianJiTwo.Location = new Point(375, 81);
                    this.Controls.Add(dianJiTwo);
                    dianJiTwo.Text = tb_shiyanclassBLL.ExperimentNameJudge(2).ToString();
                    dianJiTwo.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(3) != "")
                {
                    dianJiThree.Location = new Point(508, 81);
                    this.Controls.Add(dianJiThree);
                    dianJiThree.Text = tb_shiyanclassBLL.ExperimentNameJudge(3).ToString();
                    dianJiThree.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(4) != "")
                {
                    dianJiFour.Location = new Point(625, 81);
                    this.Controls.Add(dianJiFour);
                    dianJiFour.Text = tb_shiyanclassBLL.ExperimentNameJudge(4).ToString();
                    dianJiFour.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(5) != "")
                {
                    dianJiFive.Location = new Point(243, 146);
                    this.Controls.Add(dianJiFive);
                    dianJiFive.Text = tb_shiyanclassBLL.ExperimentNameJudge(5).ToString();
                    dianJiFive.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(6) != "")
                {
                    dianJiSix.Location = new Point(375, 146);
                    this.Controls.Add(dianJiSix);
                    dianJiSix.Text = tb_shiyanclassBLL.ExperimentNameJudge(6).ToString();
                    dianJiSix.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(7) != "")
                {
                    dianJiSeven.Location = new Point(508, 146);
                    this.Controls.Add(dianJiSeven);
                    dianJiSeven.Text = tb_shiyanclassBLL.ExperimentNameJudge(7).ToString();
                    dianJiSeven.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(8) != "")
                {
                    dianJiEight.Location = new Point(625, 146);
                    this.Controls.Add(dianJiEight);
                    dianJiEight.Text = tb_shiyanclassBLL.ExperimentNameJudge(8).ToString();
                    dianJiEight.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(9) != "")
                {
                    dianJiNine.Location = new Point(243, 220);
                    this.Controls.Add(dianJiNine);
                    dianJiNine.Text = tb_shiyanclassBLL.ExperimentNameJudge(9).ToString();
                    dianJiNine.Font = new Font("宋体", 14);
                }
                if (tb_shiyanclassBLL.ExperimentNameJudge(10) != "")
                {
                    dianJiTen.Location = new Point(375, 220);
                    this.Controls.Add(dianJiTen);
                    dianJiTen.Text = tb_shiyanclassBLL.ExperimentNameJudge(10).ToString();
                    dianJiTen.Font = new Font("宋体", 14);
                }
            }
            catch 
            { }
        }
        #endregion

    }
}
